from google.appengine.ext import webapp
from datetime import datetime
register = webapp.template.create_template_register()

@register.filter
def relative_time(value):
    if value is None:
        return "N/A"
    passed_time = datetime.now() - value
    if passed_time.days > 0:
        return str( passed_time.days )+ " day ago"
    if passed_time.seconds / 3600 > 0:
        return str(passed_time.seconds / 3600) + " hour ago"
    if passed_time.seconds / 60 > 0:
        return str(passed_time.seconds / 60 ) + " minute ago"
    else:
        return "few seconds ago"
